import request from '@/util/request'
import router from '@/router/index.js'
import lazyLoading from './lazyLoading';
import store from '@/store'
export default {
    // 左侧菜单路由生成
    async getzhycloginInfo() {
        let res = await request.zhycget('/oauth/loginInfo')
        let xias = [],
            luyouls = []
        store.state.userinfo = res.obj.user
        localStorage.companyCode = res.obj.user.companyCode
        res.obj.menus.childMenus.map((a, aa) => {
            let stair = {}
            stair.path = '/' + a.menuNameNick
            stair.name = a.menuNameEn
            stair.meta = {}
            stair.meta.title = a.menuName
            stair.title = a.menuName,
                stair.children = []
            stair.index = aa + 1
            a.childMenus.map((b, ab) => {
                let secondLevel = {
                    name: b.menuNameEn,
                    path: '/' + b.menuNameNick,
                    meta: {
                        index: stair.index + '-' + (ab + 1),
                        title: b.menuName,
                        secondLevel: a.menuName + ">" + b.menuName
                    },
                    component: lazyLoading(b.menuNameNick),
                    title: b.menuName,
                    index: stair.index + '-' + (ab + 1),
                    children: [],
                    isxia: b.childMenus.length <= 0
                }
                stair.children.push(secondLevel)
                if (b.childMenus.length > 0) {
                    b.childMenus.map((c, ac) => {
                        let threeLevel = {
                            name: c.menuNameEn,
                            path: '/' + c.menuNameNick,
                            component: lazyLoading(c.menuNameNick),
                            meta: {
                                index: stair.index + '-' + secondLevel.index + '-' + (ac + 1),
                                title: c.menuName,
                                secondLevel: a.menuName + ">" + b.menuName+ ">" + c.menuName
                            },
                            index: stair.index + '-' + secondLevel.index + '-' + (ac + 1),
                            title: c.menuName,
                        }
                        secondLevel.children.push(threeLevel)
                        luyouls.push(threeLevel)
                    })
                } else {
                    luyouls.push(secondLevel)
                }

            })
            xias.push(stair)
        })
        localStorage.luyouls = JSON.stringify(luyouls)
        router.addRoutes(luyouls)
        return xias
    }
}
